﻿namespace ExamV5.Persion
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class EditPersionInfo : Page
    {
        protected Button butDefault;
        protected DropDownList DDLEdu;
        protected DropDownList DDLGWLevel;
        protected DropDownList DDLGWName;
        protected DropDownList DDLUserSex;
        protected DropDownList DDLWorker;
        protected HtmlForm Form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected Label labUserCode;
        private PublicFun publicFun_0 = new PublicFun();
        protected TextBox txtBrithday;
        protected TextBox txtJoinDate;
        protected TextBox txtMoveTel;
        protected TextBox txtReUserPwd;
        protected TextBox txtUserName;
        protected TextBox txtUserPwd;
        protected TextBox txtUserSFZH;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            string strSql = "";
            if ((this.txtMoveTel.Text.Trim() != "") && (this.publicFun_0.GetValues("select UserCode from UserInfo where UserCode<>'" + this.httpCookie_0.Value + "' and HandCombNO='" + this.publicFun_0.CheckString(this.txtMoveTel.Text) + "'", "UserCode").Trim() != ""))
            {
                base.Response.Write("<script>alert('〖" + this.txtMoveTel.Text.Trim() + "〗手机号码已经存在,无法注册！')</script>");
            }
            else if ((this.txtUserSFZH.Text.Trim() == "") || (this.publicFun_0.GetValues("select UserCode from UserInfo where  UserCode<>'" + this.httpCookie_0.Value + "' and UserSFZH='" + this.publicFun_0.CheckString(this.txtUserSFZH.Text) + "'", "UserCode").Trim() == ""))
            {
                string text1 = this.httpCookie_0.Value;
                string str13 = this.publicFun_0.CheckString(this.txtUserName.Text);
                string str3 = "";
                if (this.txtUserPwd.Text.Trim() != "")
                {
                    str3 = FormsAuthentication.HashPasswordForStoringInConfigFile(this.publicFun_0.CheckString(this.txtUserPwd.Text), "MD5").Trim();
                    if (str3.Length > 20)
                    {
                        str3 = str3.Substring(0, 20);
                    }
                }
                string str4 = this.publicFun_0.CheckString(this.DDLUserSex.SelectedItem.Text);
                string str5 = this.publicFun_0.CheckString(this.DDLWorker.SelectedItem.Text);
                string str6 = this.publicFun_0.CheckString(this.txtBrithday.Text);
                string str7 = this.publicFun_0.CheckString(this.DDLEdu.SelectedItem.Value);
                string str8 = this.publicFun_0.CheckString(this.txtUserSFZH.Text);
                string str9 = this.publicFun_0.CheckString(this.txtJoinDate.Text);
                string str10 = this.publicFun_0.CheckString(this.txtMoveTel.Text);
                string str11 = this.publicFun_0.CheckString(this.DDLGWName.SelectedItem.Value);
                string str12 = this.publicFun_0.CheckString(this.DDLGWLevel.SelectedItem.Value);
                strSql = "update UserInfo set UserName='" + str13 + "',UserSex='" + str4 + "',Worker='" + str5 + "',HandCombNO='" + str10 + "',UserAge='" + str6 + "',JoinWorkDate='" + str9 + "',UserGWName='" + str11 + "',UserGWLevel='" + str12 + "',UserSFZH='" + str8 + "',UserEdu='" + str7 + "',UserMemo=''";
                if (str3.Trim() != "")
                {
                    strSql = strSql + ",UserPwd='" + str3 + "'";
                }
                strSql = strSql + " where UserCode='" + this.httpCookie_0.Value + "'";
                this.publicFun_0.ExecuteSql(strSql);
                base.Response.Write("<script>alert('编辑用户信息操作成功！');</script>");
            }
            else
            {
                base.Response.Write("<script>alert('〖" + this.txtUserSFZH.Text.Trim() + "〗身份证号已经存在,无法注册！')</script>");
            }
        }

        private void method_0()
        {
            try
            {
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                SqlCommand command = new SqlCommand("select * from UserInfo where UserCode='" + this.httpCookie_0.Value + "'", connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                if (reader.Read())
                {
                    this.txtUserName.Text = reader["UserName"].ToString();
                    this.DDLUserSex.SelectedIndex = -1;
                    this.DDLGWName.SelectedIndex = -1;
                    this.DDLGWLevel.SelectedIndex = -1;
                    this.DDLWorker.SelectedIndex = -1;
                    this.DDLEdu.SelectedIndex = -1;
                    this.txtMoveTel.Text = reader["HandCombNO"].ToString();
                    this.txtUserSFZH.Text = reader["UserSFZH"].ToString();
                    this.DDLWorker.Items.FindByText(reader["Worker"].ToString()).Selected = true;
                    this.DDLUserSex.Items.FindByValue(reader["UserSex"].ToString()).Selected = true;
                    this.DDLGWName.Items.FindByValue(reader["UserGWName"].ToString()).Selected = true;
                    this.DDLGWLevel.Items.FindByValue(reader["UserGWLevel"].ToString()).Selected = true;
                    this.DDLEdu.Items.FindByValue(reader["UserEdu"].ToString()).Selected = true;
                    if (reader["UserAge"].ToString().Trim() != "")
                    {
                        this.txtBrithday.Text = Convert.ToDateTime(reader["UserAge"].ToString()).ToShortDateString();
                    }
                    if (reader["JoinWorkDate"].ToString().Trim() != "")
                    {
                        this.txtJoinDate.Text = Convert.ToDateTime(reader["JoinWorkDate"].ToString()).ToShortDateString();
                    }
                }
                reader.Close();
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
            }
            catch
            {
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString;
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if (!((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false))
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
            else
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (!base.IsPostBack)
                {
                    base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    base.Response.Cache.SetNoStore();
                    if (!(this.publicFun_0.ReturnPaperData() != "Yes"))
                    {
                        this.DDLWorker.DataTextField = "ParmName";
                        this.DDLWorker.DataValueField = "ParmValue";
                        this.DDLWorker.DataSource = this.publicFun_0.RetrunDataView("select ParmName,ParmValue from SysParmInfo where ParmMemo='Worker'");
                        this.DDLWorker.DataBind();
                        ListItem item = new ListItem("--请选择--", "0");
                        this.DDLWorker.Items.Add(item);
                        this.DDLWorker.Items.FindByValue("0").Selected = true;
                        this.DDLGWName.DataTextField = "ParmName";
                        this.DDLGWName.DataValueField = "ParmValue";
                        this.DDLGWName.DataSource = this.publicFun_0.RetrunDataView("select ParmName,ParmValue from SysParmInfo where ParmMemo='GWName'");
                        this.DDLGWName.DataBind();
                        ListItem item2 = new ListItem("--请选择--", "");
                        this.DDLGWName.Items.Add(item2);
                        this.DDLGWName.Items.FindByValue("").Selected = true;
                        this.method_0();
                        this.labUserCode.Text = this.httpCookie_0.Value;
                        if (this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsStuEdit'", "ParmValue").Trim().Trim() == "N")
                        {
                            this.txtUserName.Enabled = false;
                            this.txtMoveTel.Enabled = false;
                            this.txtUserSFZH.Enabled = false;
                            this.DDLWorker.Enabled = false;
                            this.DDLUserSex.Enabled = false;
                            this.DDLGWName.Enabled = false;
                            this.DDLGWLevel.Enabled = false;
                            this.DDLEdu.Enabled = false;
                            this.txtBrithday.Enabled = false;
                            this.txtJoinDate.Enabled = false;
                        }
                    }
                    else
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请与管理员联系！')</script>");
                    }
                }
            }
        }
    }
}

